package com.wudl.report.controller;

import com.alibaba.fastjson.JSON;
import com.wudl.report.bean.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName : ReportController
 * @Description : 接口发送消息控制类
 * @Author :wudl
 * @Date: 2020-11-03 00:00
 */

@RestController
public class ReportController {


    @Autowired
    KafkaTemplate kafkaTemplate;


    @RequestMapping("/send")
    public Map<String, String> GetReceive(@RequestBody String json) {
        Map<String, String> map = new HashMap();
        try {
            Message msg = new Message();
            msg.setMessage(json);
            msg.setCount(1);
            msg.setTimeStamp(System.currentTimeMillis());

            String toMsg = JSON.toJSONString(msg);


            kafkaTemplate.send("pyg", toMsg);
            map.put("success", "true");
        } catch (Exception e) {
            System.out.println("----eeee----"+e.getMessage());
            map.put("success", "false");
        }
        return map;

    }

}
